package com.liuzhou.action.subtask;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.liuzhou.dao.ItemDao;
import com.liuzhou.dao.SubTaskDao;
import com.liuzhou.dao.impl.ItemDaoImpl;
import com.liuzhou.dao.impl.SubtaskDaoImpl;
import com.liuzhou.model.Subtask;

import net.sf.json.JSONObject;

public class SubtaskAddAction extends HttpServlet {

	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		System.out.println("进入添加子任务的的过程");
		// 获取页面数据
		try {
			// 从dao中想数据库插入一条数据
			String subtaskName =  req.getParameter("subtask_name");
			String subtaskDetail =  req.getParameter("subtask_detail");
			String subtaskItemName =  req.getParameter("subtask_item_name");
			
			ItemDao itemDao = new ItemDaoImpl();
			Integer item_id = itemDao.qureyIdByName(subtaskItemName);

			
			SubTaskDao subTaskDao = new SubtaskDaoImpl();
			subTaskDao.addSubtask(item_id, subtaskName, subtaskDetail);//子任务插入完成
			
		} catch (SQLException e) {
			e.printStackTrace();
		}
		// 向前端页面响应
		// 响应
		JSONObject json = new JSONObject();
		json.put("statusCode", "200");
		json.put("message", "OK!");
		json.put("navTabId", "productAddPage");
		json.put("rel", "productedList");
		json.put("callbackType", "closeCurrent");

		PrintWriter out = resp.getWriter();
		out.println(JSONObject.fromObject(json));
		out.flush();
		out.close();

	}

}
